package com.hongxun.modules.bss.service.impl;

import java.util.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hongxun.modules.bss.dao.DCrossCostDao;
import com.hongxun.modules.bss.entity.DCrossCostEntity;
import com.hongxun.modules.bss.service.DCrossCostService;


@Service("dCrossCostService")
public class DCrossCostServiceImpl implements DCrossCostService {
    @Autowired
    private DCrossCostDao dCrossCostDao;

    @Override
    public DCrossCostEntity queryObject(String guid) {
        return dCrossCostDao.queryObject(guid);
    }

    @Override
    public List<DCrossCostEntity> queryList(Map<String, Object> map) {
        return dCrossCostDao.queryList(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return dCrossCostDao.queryTotal(map);
    }

    @Override
    public void save(DCrossCostEntity dCrossCost) {
        if (dCrossCost.getGuid() == null || dCrossCost.getGuid().equals("")) {

            dCrossCost.setGuid(UUID.randomUUID().toString());
        }
        dCrossCostDao.save(dCrossCost);
    }

    @Override
    public void update(DCrossCostEntity dCrossCost) {
        dCrossCostDao.update(dCrossCost);
    }

    @Override
    public void delete(String guid) {
        dCrossCostDao.delete(guid);
    }

    @Override
    public void deleteBatch(String[] guids) {
        dCrossCostDao.deleteBatch(guids);
    }

    @Override
    public void insertOrReplaceOrDelete(List<DCrossCostEntity> entities) {
        for (DCrossCostEntity d : entities) {
            if (d.getCCDatastate().equals("删除")) {
                dCrossCostDao.delete(d.getGuid());
            } else {
                DCrossCostEntity dCrossCostEntity = dCrossCostDao.queryObject(d.getGuid());
                if (dCrossCostEntity == null) {
                    dCrossCostDao.save(d);
                } else {
                    dCrossCostDao.update(d);
                }
            }
        }
    }

}
